package it.mp.multitask.factory;

import android.preference.CheckBoxPreference;
import android.preference.ListPreference;
import android.preference.PreferenceGroup;
import android.preference.Preference.OnPreferenceChangeListener;
import it.mp.multitask.R;
import it.mp.multitask.Setup;
import it.mp.multitask.preference.BackgroundListPreference;
import it.mp.multitask.preference.NumberBoxPreference;
import it.mp.multitask.utility.IconCache;

public class PreferenceIphone implements Preference {

	private Setup setup;

	public PreferenceIphone(Setup setup) {
		this.setup = setup;
	}

	public void crea() {
		CheckBoxPreference cbRunning = (CheckBoxPreference) setup.findPreference("pref_running");
		NumberBoxPreference nbRunningNumber = (NumberBoxPreference) setup.findPreference(setup.getResources().getString(R.string.App_running_number));
		BackgroundListPreference blRunningTheme = (BackgroundListPreference) setup.findPreference(setup.getResources()
				.getString(R.string.pref_background_theme));

		CheckBoxPreference cbRecently = (CheckBoxPreference) setup.findPreference("pref_recently");
		NumberBoxPreference nbRecentlyNumber = (NumberBoxPreference) setup.findPreference(setup.getResources().getString(R.string.App_recently_number));
		BackgroundListPreference blRecentlyTheme = (BackgroundListPreference) setup.findPreference(setup.getResources().getString(
				R.string.pref_background_theme_rc));

		CheckBoxPreference cbService = (CheckBoxPreference) setup.findPreference("pref_service");
		NumberBoxPreference nbServiceNumber = (NumberBoxPreference) setup.findPreference(setup.getResources().getString(R.string.App_service_number));
		BackgroundListPreference blServiceTheme = (BackgroundListPreference) setup.findPreference(setup.getResources().getString(
				R.string.pref_background_theme_srv));

		PreferenceGroup pgPreferred = (PreferenceGroup) setup.findPreference(setup.getResources().getString(R.string.App_preferred));
		BackgroundListPreference blPreferredTheme = (BackgroundListPreference) setup.findPreference(setup.getResources().getString(
				R.string.pref_background_theme_pa));

		PreferenceGroup pgBlackList = (PreferenceGroup) setup.findPreference(setup.getResources().getString(R.string.App_not_show));

		CheckBoxPreference cbSectionOrder = (CheckBoxPreference) setup.findPreference(setup.getResources().getString(R.string.app_alphabetic_order));
		NumberBoxPreference nbMargin = (NumberBoxPreference) setup.findPreference(setup.getResources().getString(R.string.theme_margin));

		ListPreference lpMode = (ListPreference) setup.findPreference(setup.getResources().getString(R.string.theme_mode));
		CheckBoxPreference cbDoubleClick = (CheckBoxPreference) setup.findPreference(setup.getResources().getString(R.string.app_double_click));
		CheckBoxPreference cbShowTitle = (CheckBoxPreference) setup.findPreference(setup.getResources().getString(R.string.show_title));
		CheckBoxPreference cbShowMemory = (CheckBoxPreference) setup.findPreference(setup.getResources().getString(R.string.app_show_available_memory));

		CheckBoxPreference cbShowDeleted = (CheckBoxPreference) setup.findPreference(setup.getResources().getString(R.string.app_show_app_deleted_by_system));
		CheckBoxPreference cbShowRecycledBin = (CheckBoxPreference) setup.findPreference(setup.getResources().getString(R.string.app_recycle_bin));

		CheckBoxPreference cbShowTitleApps = (CheckBoxPreference) setup.findPreference(setup.getResources().getString(R.string.app_show_title));
		ListPreference lpIconDimension = (ListPreference) setup.findPreference(setup.getResources().getString(R.string.app_title_size));
		CheckBoxPreference cbAudio = (CheckBoxPreference) setup.findPreference(setup.getResources().getString(R.string.audio_controls));

		lpIconDimension.setOnPreferenceChangeListener(new OnPreferenceChangeListener() {

			public boolean onPreferenceChange(android.preference.Preference arg0, Object arg1) {
				IconCache.hmIcone.clear();
				return true;
			}

		});

		ListPreference blGlobal = (ListPreference) setup.findPreference(setup.getResources().getString(R.string.pref_background));
		blGlobal.setEnabled(true);

		cbRunning.setEnabled(true);
		nbRunningNumber.setEnabled(true);
		blRunningTheme.setEnabled(false);

		cbRecently.setEnabled(true);
		nbRecentlyNumber.setEnabled(true);
		blRecentlyTheme.setEnabled(false);

		cbService.setEnabled(true);
		nbServiceNumber.setEnabled(true);
		blServiceTheme.setEnabled(false);

		pgPreferred.setEnabled(true);
		blPreferredTheme.setEnabled(false);

		pgBlackList.setEnabled(true);

		cbSectionOrder.setEnabled(true);
		nbMargin.setEnabled(true);

		lpMode.setEnabled(true);
		cbDoubleClick.setEnabled(true);
		cbShowTitle.setEnabled(true);
		cbShowMemory.setEnabled(true);

		cbShowDeleted.setEnabled(true);
		cbShowRecycledBin.setEnabled(true);

		cbShowTitleApps.setEnabled(false);
		lpIconDimension.setEnabled(true);

		cbAudio.setEnabled(true);
	}

}
